package cn.dansj.common.utils.bean;

import cn.dansj.common.utils.enums.GlobalEnv;
import cn.dansj.common.utils.transfer.DateTime;
import cn.dansj.common.utils.transfer.DefaultMethods;
import cn.dansj.common.utils.transfer.RandomUtils;

import java.io.Serializable;

/*
 * 登录后封装用户信息返回uuid给前端
 * */
public class CacheToken extends DefaultMethods implements Serializable {
    private static final long serialVersionUID = GlobalEnv.SerialVersionUID;
    private String username;
    private String role;
    private String sequence;
    private String platform;
    private String uuid = RandomUtils.sequence();
    private long loginTime = System.currentTimeMillis();
    private long expireTime = System.currentTimeMillis();
    private long lastActiveTime = System.currentTimeMillis();
    // 判断允许手机端还是pc还是不限制
    private int allowLoginFrom;
    private boolean isMobile;
    private String apiToken;

    public CacheToken(String username, String role, String sequence, boolean isMobile) {
        this.username = username;
        this.role = role;
        this.sequence = sequence;
        this.isMobile = isMobile;
    }

    public CacheToken() {

    }

    public String getUsername() {
        return username;
    }

    public String getRole() {
        return role;
    }

    public String getSequence() {
        return sequence;
    }

    public String getUuid() {
        return uuid;
    }

    public DateTime getLoginTime() {
        return DateTime.getInstance(loginTime);
    }

    public DateTime getLastActiveTime() {
        return DateTime.getInstance(lastActiveTime);
    }

    public void setLastActiveTime(long lastActiveTime) {
        this.lastActiveTime = lastActiveTime;
    }

    public void setLastActiveTime(String lastActiveTime) {
        this.lastActiveTime = DateTime.getInstance(lastActiveTime).getTimeInMillis();
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    public void setLoginTime(long loginTime) {
        this.loginTime = loginTime;
    }

    public void setLoginTime(String loginTime) {
        this.loginTime = DateTime.getInstance(loginTime).getTimeInMillis();
    }

    public void setSequence(String sequence) {
        this.sequence = sequence;
    }

    public void setRole(String role) {
        this.role = role;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public void setExpireTime(long expireTime) {
        this.expireTime = expireTime;
    }

    public void setExpireTime(String expireTime) {
        this.expireTime = DateTime.getInstance(expireTime).getTimeInMillis();
    }

    public DateTime getExpireTime() {
        return DateTime.getInstance(expireTime);
    }

    public int getAllowLoginFrom() {
        return allowLoginFrom;
    }

    public void setAllowLoginFrom(int allowLoginFrom) {
        this.allowLoginFrom = allowLoginFrom;
    }

    public boolean isMobile() {
        return isMobile;
    }

    public void setMobile(boolean mobile) {
        isMobile = mobile;
    }

    public String getPlatform() {
        return platform;
    }

    public void setPlatform(String platform) {
        this.platform = platform;
    }

    public String getApiToken() {
        return apiToken;
    }

    public void setApiToken(String apiToken) {
        this.apiToken = apiToken;
    }
}
